#ifndef COSHIP_AMR_CODEC_H
#define COSHIP_AMR_CODEC_H

#ifdef __cplusplus
extern "C" {
#endif

typedef unsigned char uint8_t;
typedef __int64 int64_t;
typedef unsigned int uint32_t;
typedef short int16_t;
typedef char int8_t;
typedef unsigned __int64 uint64_t;



typedef struct {
	/**
	* id
	* - encoding: Set by user.
	* - decoding: Set by libavcodec.
	*/
	int id;

	/**
	* width and height in 1/16 pel
	* - encoding: Set by user.
	* - decoding: Set by libavcodec.
	*/
	int width;
	int height;

	/**
	* position of the top left corner in 1/16 pel for up to 3 fields/frames
	* - encoding: Set by user.
	* - decoding: Set by libavcodec.
	*/
	int16_t position[3][2];
}AVPanScan;

typedef struct {
	uint8_t *data[4];
	int linesize[4];
	uint8_t *base[4];
	int key_frame;
	int pict_type;
	int64_t pts;
	int coded_picture_number;
	int display_picture_number;
	int quality; 
	int age;
	int reference;
	int8_t *qscale_table;
	int qstride;
	uint8_t *mbskip_table;
	int16_t (*motion_val[2])[2];
	uint32_t *mb_type;
	uint8_t motion_subsample_log2;
	void *opaque;
	uint64_t error[4];
	int type;
	int repeat_pict;
	int qscale_type;
	int interlaced_frame;
	int top_field_first;
	AVPanScan *pan_scan;
	int palette_has_changed;
	int buffer_hints;
	short *dct_coeff;
	int8_t *ref_index[2];
	int64_t reordered_opaque;
}AVFrame;

typedef enum {
	CODEC_ID_AMR_NB,
	CODEC_ID_AMR_WB,
} CODEC_ID;

typedef enum {
	SAMPLE_FMT_S16,
} SAMPLEFMT;

typedef struct {
	CODEC_ID codec_id;
	unsigned int sample_rate;
	unsigned int channels;
	unsigned int frame_size;
	SAMPLEFMT sample_fmt;
	void *priv_data;
	AVFrame * coded_frame;
	int bit_rate;
} AVCodecContext;

typedef struct AMRContext {
	int frameCount;
	void * decState;
	int *enstate;
	int enc_bitrate;
} AMRContext;

typedef struct AMRWBContext {
	int frameCount;
	void *state;
	int mode;
	short allow_dtx;
} AMRWBContext;

int amr_nb_encode_init(AVCodecContext * avctx);
int amr_nb_encode_close(AVCodecContext * avctx);
int amr_nb_encode_frame(AVCodecContext *avctx,
						unsigned char *frame/*out*/, int buf_size, void *data/*in*/);

int amr_nb_decode_init(AVCodecContext * avctx);
int amr_nb_decode_close(AVCodecContext * avctx);
int amr_nb_decode_frame(AVCodecContext * avctx,
						void *data, int *data_size,
						uint8_t * buf, int buf_size);

int amr_wb_encode_init(AVCodecContext * avctx);
int amr_wb_encode_close(AVCodecContext * avctx);
int amr_wb_encode_frame(AVCodecContext *avctx,
						unsigned char *frame/*out*/, int buf_size, void *data/*in*/);

int amr_wb_decode_init(AVCodecContext * avctx);
int amr_wb_decode_close(AVCodecContext * avctx);
int amr_wb_decode_frame(AVCodecContext * avctx,
						void *data, int *data_size,
						uint8_t * buf, int buf_size);

#ifdef __cplusplus
}
#endif

#endif
